package net.stogi.unicore.beyond.ui.client.taskeditor.taskpreview;

import java.util.HashMap;
import java.util.Map;

import net.stogi.common.gwt.dispatch.client.core.ActionManager;
import net.stogi.common.gwt.frame.client.core.EventBus;
import net.stogi.common.gwt.frame.client.module.Module;
import net.stogi.common.gwt.frame.client.mvp.AbstractPresenter;

import com.google.gwt.user.client.ui.Widget;

public class TaskPreviewModule implements Module {

	public static final String TASK_PREVIEW_PRESENTER = "task-preview-presenter";

	public static final String TASK_PREVIEW_WIDGET = "task-preview-widget";

	private ActionManager actionManager;

	private EventBus eventBus;

	private Map<String, AbstractPresenter> presenterMap = new HashMap<String, AbstractPresenter>();

	private Map<String, Widget> widgetMap = new HashMap<String, Widget>();

	public TaskPreviewModule(ActionManager actionManager, EventBus eventBus) {
		this.actionManager = actionManager;
		this.eventBus = eventBus;
		initModule();
	}

	@Override
	public Widget getWidget(String name) {
		return widgetMap.get(name);
	}

	protected void initModule() {
		TaskPreviewWidget taskPreviewWidget = new TaskPreviewWidget();
		TaskPreviewPresenter taskPreviewPresenter = new TaskPreviewPresenter(taskPreviewWidget, actionManager, eventBus);
		// Register widgets and presenters.
		widgetMap.put(TASK_PREVIEW_WIDGET, taskPreviewWidget);
		presenterMap.put(TASK_PREVIEW_PRESENTER, taskPreviewPresenter);
	}
}
